﻿import com.dinmax.isolution.*

class BlindGUI
extends MovieClip {
	
	private var device:Blind;
	private var listener:WindowDeviceGUI;
	
	function BlindGUI(){
		if(this._parent._parent instanceof WindowDeviceGUI)	this.listener = WindowDeviceGUI(this._parent._parent);
				
		return;
	}
		
	public function getDevice():Blind{
		return this.device;
	}
	public function setDevice(newDevice:Blind):Void{
		
		this.device = newDevice;
		this.refresh();
		return;
	}
	
	public function setSelected(b:Boolean):Void {
		
		if(b){
			this.gotoAndStop(2);
			listener.showDeviceView(device);			
			
		} else {
			this.gotoAndStop(1);	
		}
		return;
	}
	
	public function getSelected():Boolean{
		return (this._currentframe == 2);
	}
	
	public function refresh():Void {
			
		this["txt_title"].text = this.device.getName();
		this["txt_group"].text = this.device.getGroup();
		var val:Number = this.device.getValue();
		
		this["mcState"].setPos(val);
		this["txt_value"].text = Math.round(val)+"%";
		this["mcValue"].mcLuz.gotoAndStop(Math.floor(val/10+1));	
		 
		return;
	}
	
	public function registerChild(mc:MovieClip):Void {
		if(mc == this["mcIcon"]){
			mc.gotoAndStop(2);
			mc.setPos(6);
		} else if(mc == this["mcState"]){
			//trace(this.device.getValue());
			mc.setPos(this.device.getValue());
		}
		return;
	}
	
}